<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class news_detail_model extends Model
{
	var $url_prefix2 = 'admin/news.news.lists';
	var $url_prefix = 'admin/news.news.detail';
	var $start_segment = 3;
	var $start;
	var $msg_cache_prefix = 'msg';
	var $cache;
	var $cache_name = 'news';
	var $item_segment = 4;
	var $item;
	var $_table_name = NEWS;
	function news_detail_model()
	{
		parent::Model();
		
		global $CI;
		//check language
		$language = $CI->uri->segment(3);
		if($language=="english"){
			$this->url_prefix2 = $this->url_prefix2."/english";
			$this->url_prefix = $this->url_prefix."/english";
			$this->start_segment = $this->start_segment+1;
			$this->item_segment = $this->item_segment+1;
			$this->_table_name = $this->_table_name."_en";			
		}
		$start = $CI->uri->segment($this->start_segment);
		$this->start = $start?$start:0;
		
		$item = $CI->uri->segment($this->item_segment);
		$this->item = $item?$item:0;
		
		$this->cache = new Session_lite($this->cache_name);
	}
	
	function maxkey()
	{
		$this->db->select_max(NEWS_NEWS_ID);
		$row = $q->row();
		return $row?($row->{NEWS_NEWS_ID}+1):1;
	}
	
	function admin_id()
	{
		global $CI;
		$a = $CI->session->userdata('admin_auth_logged');
		return $a['admin_id'];
	}
	
	function hasNEWS()
	{
		$q = $this->db->get_where($this->_table_name, array( NEWS_NEWS_ID=>$this->item));
		return $q->num_rows()>0;
	}	
	
	function check()
	{
		global $CI;
		$title = $CI->input->post('title');
		if ($this->item)
		{
			$this->db->where(NEWS_NEWS_ID.' != '.$this->item);
			$q = $this->db->get_where($this->_table_name, array(NEWS_TITLE=>$title));
		} else
			$q = $this->db->get_where($this->_table_name, array( NEWS_TITLE=>$title));
		return $q->num_rows()==0;
	}
}

?>
